home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume91
/
midi
/
casio
/
part01
/
cleanup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-28
|
1KB
|
87 lines
/* cleanup - Peter and Karl's standard cleanup management
*
* "cleaned up" the documentation 3/1/88
*
*/
#include <exec/types.h>
#include <functions.h>
#include <exec/memory.h>
#include <stdio.h>
struct _clean
{
int (*function)();
struct _clean *next;
} *cleanlist = NULL;
/* add_cleanup
* given a function, add it to a list of functions to call when cleanup
* is executed
*/
add_cleanup(function)
int (*function)();
{
struct _clean *ptr;
ptr = AllocMem(sizeof(struct _clean), MEMF_PUBLIC);
if(!ptr)
return 0;
ptr->function = function;
ptr->next = cleanlist;
cleanlist = ptr;
}
/* cleanup
* call all the functions that were passed as arguments to add_cleanup
* this run
*/
cleanup()
{
struct _clean *ptr;
int (*f)();
fflush(stdout);
fflush(stderr);
while(cleanlist)
{
/* locate the next cleanup function and get the function pointer */
ptr = cleanlist;
cleanlist = cleanlist->next;
f = ptr->function;
/* cleanup must clean up after itself */
FreeMem(ptr, sizeof(struct _clean));
/* execute the function */
(*f)();
fflush(stdout);
fflush(stderr);
}
}
/* panic - abort with an error message */
short panic_in_progress = 0;
panic(s)
char *s;
{
fflush(stdout);
fprintf(stderr,"panic: %s\n",s);
fflush(stderr);
if (!panic_in_progress)
{
cleanup();
exit(10);
}
fprintf(stderr,"double panic!\n");
}
_abort()
{
panic("^C or other C library abort");
}